package erp.server.message.controller;

import erp.server.base.response.JsonResult;
import erp.server.base.response.StatusCode;
import erp.server.message.enums.BoxType;
import erp.server.message.pojo.dto.BoxOperationDTO;
import erp.server.message.pojo.dto.BoxSearchDTO;
import erp.server.message.pojo.dto.MessageCopyDTO;
import erp.server.message.pojo.dto.MessageSaveDTO;
import erp.server.message.pojo.vo.MessageListVO;
import erp.server.message.pojo.vo.MessageVO;
import erp.server.message.service.BoxService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 信箱操作
 */
@Slf4j
@RestController
@RequestMapping("/isms/message/box")
public class BoxController {
    @Autowired
    private BoxService boxService;

    /**
     * 获取信箱消息列表
     * @return 信箱中所有消息
     */
    @GetMapping("/get_messages")
    public JsonResult getMessages(BoxSearchDTO boxSearchDTO) {
        log.debug("查询信箱消息列表 boxSearchDTO: {}", boxSearchDTO);
        List<MessageListVO> messageVOS;

        messageVOS = boxService.selectMessages(boxSearchDTO);

        return new JsonResult(StatusCode.OPERATION_MESSAGE_SUCCESS,messageVOS);
    }


    /**
     * 删除信箱消息
     */
    @DeleteMapping("/delete_message")
    public JsonResult deleteMessage(BoxOperationDTO boxOperationDTO) {
        log.debug("删除信箱中的指定消息 boxOperationDTO: {}", boxOperationDTO);
        boxService.deleteMessage(boxOperationDTO);
        return new JsonResult(StatusCode.OPERATION_MESSAGE_SUCCESS);
    }


    /**
     * 收藏消息
     * @param messageCopyDTO 需要当前保存的消息id,消息当前所处信箱
     */
    @PostMapping("/save_to_collect")
    public JsonResult saveToCollect(MessageCopyDTO messageCopyDTO) {
        log.debug("收藏消息 messageCopyDTO: {}", messageCopyDTO);
        messageCopyDTO.setDesBox(BoxType.COLLECTBOX);
        boxService.copyMessage(messageCopyDTO);
        return new JsonResult(StatusCode.OPERATION_MESSAGE_SUCCESS);
    }










}


















































